package com.example.month11.festivalsms.bean;

import java.util.ArrayList;
import java.util.List;

/**
 * 单例提供数据
 */
public class FestivalLab {

    public static FestivalLab mInstance;
    private List<Festival> mFestivals = new ArrayList<>();
    private List<Msg> mMsgs = new ArrayList<>();

    private FestivalLab() {
        mFestivals.add(new Festival(1, "国庆节"));
        mFestivals.add(new Festival(2, "中秋节"));
        mFestivals.add(new Festival(3, "元旦"));
        mFestivals.add(new Festival(4, "春节"));
        mFestivals.add(new Festival(5, "端午节"));
        mFestivals.add(new Festival(6, "七夕节"));
        mFestivals.add(new Festival(7, "圣诞节"));
        mFestivals.add(new Festival(8, "儿童节"));

        mMsgs.add(new Msg(1, 1, "1长沙市中医药健康管理培训班举办"));
        mMsgs.add(new Msg(2, 1, "2长沙天心法院多举措优化法治化营商环境"));
        mMsgs.add(new Msg(3, 1, "3湖南长沙：“能工巧匠”大比武"));
        mMsgs.add(new Msg(4, 1, "4长沙这所高中举行首届校园歌手大赛"));
        mMsgs.add(new Msg(5, 1, "5今年快递业务旺季，湖南快递将达10亿件"));
        mMsgs.add(new Msg(6, 1, "6湖南乡村振兴交流会在长沙召开"));
        mMsgs.add(new Msg(7, 2, "7长沙汽车南站公交始发区焕新"));
        mMsgs.add(new Msg(8, 2, "8长沙天心区城区新增10处“两尺一线”"));
        mMsgs.add(new Msg(9, 2, "9长沙海鲜自助大鱼海堂被曝突然停业"));
        mMsgs.add(new Msg(10, 3, "10第三届全国花鼓戏优秀剧目展演长沙开幕"));
        mMsgs.add(new Msg(11, 3, "11第三届全国花鼓戏优秀剧目展演长沙开幕"));
        mMsgs.add(new Msg(12, 4, "12第三届全国花鼓戏优秀剧目展演长沙开幕"));
    }

    public List<Msg> getMsgsByFestivalId(int fesId) {
        List<Msg> msgs = new ArrayList<>();
        for (Msg msg : mMsgs) {
            if (msg.getFestivalId() == fesId) {
                msgs.add(msg);
            }
        }
        return msgs;
    }

    public Msg getMsgByMsgId(int msgId) {
        for (Msg msg : mMsgs) {
            if (msg.getId() == msgId)
                return msg;
        }
        return null;
    }

    public List<Festival> getFestivals() {
        // 复制一个副本。
        return new ArrayList<>(mFestivals);
    }

    // 查询数据
    public Festival getFestivalById(int id) {
        for (Festival festival : mFestivals) {
            if (festival.getId() == id)
                return festival;
        }
        return null;
    }

    public static FestivalLab getInstance() {
        if (mInstance == null) {
            synchronized (FestivalLab.class) {
                if (mInstance == null) mInstance = new FestivalLab();
            }
        }
        return mInstance;
    }

}
